﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace MauThuTabControl
{
    /// <summary>
    /// Interaction logic for TimKiem.xaml
    /// </summary>
   
    public partial class TimKiem : Page
    {
        ConnectionDB cn = new ConnectionDB();
        
        public TimKiem()
        {
            InitializeComponent();
           
            
           
        }

        void LoadCB() 
        {
            DataTable dt = cn.LoadData("select * from DMHangSX");
            DataTable dt1 = cn.LoadData("select * from DMNhomSP");


            _cbHSX.DisplayMemberPath ="tenHSX";
            _cbHSX.SelectedValuePath = "maHSX";
            _cbHSX.ItemsSource = dt.DefaultView;
            _cbHSX.SelectedIndex = -1;
            
            

            _cbNhomSP.DisplayMemberPath = "tenNhomSP";
            _cbNhomSP.SelectedValuePath = "maNhomSP";
            _cbNhomSP.ItemsSource = dt1.DefaultView;
            _cbNhomSP.SelectedIndex = -1;
        }

        private void _chNhomSP_Checked(object sender, RoutedEventArgs e)
        {
            _cbNhomSP.IsEnabled = true;
            _cbNhomSP.SelectedIndex = 0;
        }

        private void _chNhomSP_Unchecked(object sender, RoutedEventArgs e)
        {
            _cbNhomSP.IsEnabled = false;
            _cbNhomSP.SelectedIndex = -1;
        }

        private void _chHSX_Checked(object sender, RoutedEventArgs e)
        {
            _cbHSX.IsEnabled = true;
            _cbHSX.SelectedIndex = 0;
            
        }

        private void _chHSX_Unchecked(object sender, RoutedEventArgs e)
        {
            _cbHSX.IsEnabled = false;
            _cbHSX.SelectedIndex = -1;
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ktchexboxt();
            LoadCB(); 
           
           
        }
        private void ktchexboxt() 
        {
            if (_chHSX.IsChecked == true)
            {
                _cbHSX.IsEnabled = true;
                
            }
            else 
            {
                _cbHSX.IsEnabled = false;
            }

            if (_chNhomSP.IsChecked == true)
            {
                _cbNhomSP.IsEnabled = true;
                
            }
            else 
            {
                _cbNhomSP.IsEnabled = false;
            }

            if (_chGiaBan.IsChecked == true)
            {
                _txtDenGB.IsEnabled = true;
                _txtTuGB.IsEnabled = true;
            }
            else 
            {
                _txtDenGB.IsEnabled = false;
                _txtTuGB.IsEnabled = false;
            }

            
           
        }

        private void _chGiaBan_Checked(object sender, RoutedEventArgs e)
        {
            _txtDenGB.IsEnabled = true;
            _txtTuGB.IsEnabled = true;
        }

        private void _chGiaBan_Unchecked(object sender, RoutedEventArgs e)
        {
            _txtDenGB.IsEnabled = false;
            _txtTuGB.IsEnabled = false;
            _txtDenGB.Text = "0";
            _txtTuGB.Text = "0";
        }

      

       

        private void _btTimKiem_Click(object sender, RoutedEventArgs e)
        {
            if (_txtTenSP.Text != "")
            {
                DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
               " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
               " FROM dbo.DMDonViTinh INNER JOIN " +
               " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
               " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
               " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%'");
                _dtgdonvitinh.ItemsSource = dt.DefaultView;
               

            }
            else
            {
                MessageBox.Show("Nhập thông tin tìm kiếm", "Chú ý");
            }
        }

        //private void _cbNhomSP_SelectionChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    if (kttimkiem() == true)
        //    {
        //        float TGB = float.Parse(_txtTuGB.Text);
        //        float DGB = float.Parse(_txtDenGB.Text);
        //        if (_chHSX.IsChecked == false && _chGiaBan.IsChecked == false && _txtTenSP.Text == "")
        //        {
        //            if (_cbNhomSP.SelectedIndex !=-1)
        //            {
        //                DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //              " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //              " FROM dbo.DMDonViTinh INNER JOIN " +
        //              " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //              " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //              " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "'");
        //                _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //            }
        //        }
        //        else
        //        {

        //            if (_chHSX.IsChecked == false && _chGiaBan.IsChecked == false)
        //            {
        //                if (_cbNhomSP.SelectedIndex !=-1)
        //                {
        //                    DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //             " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //             " FROM dbo.DMDonViTinh INNER JOIN " +
        //             " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //             " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //             " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' ");
        //                    _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                }
        //            }
        //            else
        //            {
        //                if (_txtTenSP.Text == "" && _chGiaBan.IsChecked == false)
        //                {
        //                    if (_cbNhomSP.SelectedIndex !=-1)
        //                    {
        //                        DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                 " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                 " FROM dbo.DMDonViTinh INNER JOIN " +
        //                 " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                 " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                 " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' ");
        //                        _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                    }
        //                }
        //                else
        //                {
        //                    if (_txtTenSP.Text == "" && _chHSX.IsChecked == false)
        //                    {

        //                        if (_cbNhomSP.SelectedIndex !=-1)
        //                        {
        //                            DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                     " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                     " FROM dbo.DMDonViTinh INNER JOIN " +
        //                     " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                     " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                     " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "'and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' ");
        //                            _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                        }
        //                    }
        //                    else
        //                    {
        //                        if (_chGiaBan.IsChecked == false)
        //                        {
        //                            if (_cbNhomSP.SelectedIndex !=-1)
        //                            {
        //                                DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                         " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                         " FROM dbo.DMDonViTinh INNER JOIN " +
        //                         " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                         " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                         " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' ");
        //                                _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                            }
        //                        }
        //                        else
        //                        {
        //                            if (_chHSX.IsChecked == false)
        //                            {

        //                                if (_cbNhomSP.SelectedIndex !=-1)
        //                                {
        //                                    DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                             " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                             " FROM dbo.DMDonViTinh INNER JOIN " +
        //                             " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                             " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                             " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "'and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' ");
        //                                    _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (_txtTenSP.Text == "")
        //                                {
        //                                    if (_cbNhomSP.SelectedIndex !=-1)
        //                                    {
        //                                        DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                                 " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                                 " FROM dbo.DMDonViTinh INNER JOIN " +
        //                                 " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                                 " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                                 " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "'and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' ");
        //                                        _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                                    }
        //                                }
        //                                else
        //                                {
        //                                    if (_cbNhomSP.SelectedIndex !=-1)
        //                                    {
        //                                        DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                                 " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                                 " FROM dbo.DMDonViTinh INNER JOIN " +
        //                                 " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                                 " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                                 " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' ");
        //                                        _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                                    }
        //                                }


        //                            }
        //                        }
        //                    }
        //                }
        //            }

        //        }
        //    }
        //    else  
        //    {
        //        MessageBox.Show("Giá bán chưa hơp lệ", "Chú ý");
        //    }
        //  }

        
        
        //private void _cbHSX_SelectionChanged(object sender, SelectionChangedEventArgs e)
        //{
           
        //    if (kttimkiem() == true)
        //    {
        //        float TGB = float.Parse(_txtTuGB.Text);
        //        float DGB = float.Parse(_txtDenGB.Text);
        //        if (_chNhomSP.IsChecked == false && _chGiaBan.IsChecked == false && _txtTenSP.Text == "")
        //        {
        //            if (_cbHSX.SelectedIndex !=-1)
        //            {
        //                DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //              " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //              " FROM dbo.DMDonViTinh INNER JOIN " +
        //              " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //              " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //              " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "'");
        //                _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //            }
        //        }
        //        else
        //        {

        //            if (_chNhomSP.IsChecked == false && _chGiaBan.IsChecked == false)
        //            {
        //                if (_cbHSX.SelectedIndex !=-1)
        //                {
        //                    DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //             " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //             " FROM dbo.DMDonViTinh INNER JOIN " +
        //             " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //             " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //             " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' ");
        //                    _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                }
        //            }
        //            else
        //            {
        //                if (_txtTenSP.Text == "" && _chGiaBan.IsChecked == false)
        //                {
        //                    if (_cbHSX.SelectedIndex !=-1)
        //                    {
        //                        DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                 " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                 " FROM dbo.DMDonViTinh INNER JOIN " +
        //                 " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                 " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                 " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' ");
        //                        _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                    }
        //                }
        //                else
        //                {
        //                    if (_txtTenSP.Text == "" && _chNhomSP.IsChecked == false)
        //                    {

        //                        if (_cbHSX.SelectedIndex !=-1)
        //                        {
        //                            DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                     " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                     " FROM dbo.DMDonViTinh INNER JOIN " +
        //                     " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                     " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                     " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "'and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' ");
        //                            _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                        }
        //                    }
        //                    else
        //                    {
        //                        if (_chGiaBan.IsChecked == false)
        //                        {
        //                            if (_cbHSX.SelectedIndex !=-1)
        //                            {
        //                                DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                         " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                         " FROM dbo.DMDonViTinh INNER JOIN " +
        //                         " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                         " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                         " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' ");
        //                                _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                            }
        //                        }
        //                        else
        //                        {
        //                            if (_chNhomSP.IsChecked == false)
        //                            {

        //                                if (_cbHSX.SelectedIndex !=-1)
        //                                {
        //                                    DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                             " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                             " FROM dbo.DMDonViTinh INNER JOIN " +
        //                             " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                             " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                             " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "'and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' ");
        //                                    _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (_txtTenSP.Text == "")
        //                                {
        //                                    if (_cbHSX.SelectedIndex !=-1)
        //                                    {
        //                                        DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                                 " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                                 " FROM dbo.DMDonViTinh INNER JOIN " +
        //                                 " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                                 " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                                 " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "'and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' ");
        //                                        _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                                    }
        //                                }
        //                                else
        //                                {
        //                                    if (_cbNhomSP.SelectedIndex !=-1)
        //                                    {
        //                                        DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
        //                                 " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
        //                                 " FROM dbo.DMDonViTinh INNER JOIN " +
        //                                 " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
        //                                 " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
        //                                 " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' ");
        //                                        _dtgdonvitinh.ItemsSource = dt.DefaultView;
        //                                    }
        //                                }


        //                            }
        //                        }
        //                    }
        //                }
        //            }

        //        }
        //    }
        //    else { MessageBox.Show("Giá bán chưa hơp lệ","Chú ý"); }

        //}

        private void _btLoc_Click(object sender, RoutedEventArgs e)
        {
            if (_chNhomSP.IsChecked == false && _chGiaBan.IsChecked == false && _txtTenSP.Text == "" && _chHSX.IsChecked == false && _cbHSX.SelectedIndex==-1 && _cbNhomSP.SelectedIndex==-1)
            {
                MessageBox.Show("Không đủ thông tin để lọc", "Chú ý");
            }
            else
            {
                if (kttimkiem() == true)
                {
                    float TGB = float.Parse(_txtTuGB.Text);
                    float DGB = float.Parse(_txtDenGB.Text);
                    if (_chNhomSP.IsChecked == false && _chGiaBan.IsChecked == false && _chHSX.IsChecked == false)
                    {
                        DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
              " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
              " FROM dbo.DMDonViTinh INNER JOIN " +
              " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
              " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
              " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%'");
                        _dtgdonvitinh.ItemsSource = dt.DefaultView;
                    }
                    else
                    {
                        if (_chNhomSP.IsChecked == false && _chGiaBan.IsChecked == false && _txtTenSP.Text == "")
                        {
                            if (_cbHSX.SelectedIndex !=-1)
                            {
                                DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                              " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                              " FROM dbo.DMDonViTinh INNER JOIN " +
                              " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                              " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                              " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "'");
                                _dtgdonvitinh.ItemsSource = dt.DefaultView;
                            }
                        }
                        else
                        {
                            if (_chHSX.IsChecked == false && _chGiaBan.IsChecked == false && _txtTenSP.Text == "")
                            {
                                if (_cbNhomSP.SelectedIndex !=-1)
                                {
                                    DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                  " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                  " FROM dbo.DMDonViTinh INNER JOIN " +
                                  " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                  " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                  " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "'");
                                    _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                }
                            }
                            else
                            {
                                if (_chNhomSP.IsChecked == false && _chHSX.IsChecked == false && _txtTenSP.Text == "")
                                {
                                    DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                        " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                        " FROM dbo.DMDonViTinh INNER JOIN " +
                                        " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                        " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                        " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' ");
                                    _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                }
                                else
                                {
                                    if (_chNhomSP.IsChecked == false && _chGiaBan.IsChecked == false)
                                    {
                                        if (_cbHSX.SelectedIndex !=-1)
                                        {
                                            DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                     " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                     " FROM dbo.DMDonViTinh INNER JOIN " +
                                     " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                     " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                     " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' ");
                                            _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                        }
                                    }
                                    else
                                    {
                                        if (_txtTenSP.Text == "" && _chGiaBan.IsChecked == false)
                                        {
                                            if (_cbHSX.SelectedIndex !=-1 && _cbNhomSP.SelectedIndex !=-1)
                                            {
                                                DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                         " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                         " FROM dbo.DMDonViTinh INNER JOIN " +
                                         " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                         " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                         " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' ");
                                                _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                            }
                                        }
                                        else
                                        {
                                            if (_txtTenSP.Text == "" && _chNhomSP.IsChecked == false)
                                            {

                                                if (_cbHSX.SelectedIndex !=-1)
                                                {
                                                    DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                             " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                             " FROM dbo.DMDonViTinh INNER JOIN " +
                                             " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                             " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                             " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "'and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' ");
                                                    _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                                }
                                            }
                                            else
                                            {
                                                if (_chHSX.IsChecked == false && _chGiaBan.IsChecked == false)
                                                {
                                                    if (_cbNhomSP.SelectedIndex !=-1)
                                                    {
                                                        DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                                 " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                                 " FROM dbo.DMDonViTinh INNER JOIN " +
                                                 " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                                 " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                                 " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' ");
                                                        _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                                    }
                                                }
                                                else
                                                {
                                                    if (_txtTenSP.Text == "" && _chHSX.IsChecked == false)
                                                    {

                                                        if (_cbNhomSP.SelectedIndex !=-1)
                                                        {
                                                            DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                                     " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                                     " FROM dbo.DMDonViTinh INNER JOIN " +
                                                     " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                                     " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                                     " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "'and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' ");
                                                            _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (_chHSX.IsChecked == false && _chNhomSP.IsChecked == false)
                                                        {
                                                            DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                                    " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                                    " FROM dbo.DMDonViTinh INNER JOIN " +
                                                    " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                                    " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                                    " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.tenSanPham = N'%" + _txtTenSP.Text + "%' and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' ");
                                                            _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                                        }
                                                        else
                                                        {
                                                            if (_chGiaBan.IsChecked == false)
                                                            {
                                                                if (_cbHSX.SelectedIndex !=-1 && _cbNhomSP.Text!="")
                                                                {
                                                                    DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                                             " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                                             " FROM dbo.DMDonViTinh INNER JOIN " +
                                                             " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                                             " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                                             " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' ");
                                                                    _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (_chNhomSP.IsChecked == false)
                                                                {

                                                                    if (_cbHSX.SelectedIndex !=-1)
                                                                    {
                                                                        DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                                                 " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                                                 " FROM dbo.DMDonViTinh INNER JOIN " +
                                                                 " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                                                 " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                                                 " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "'and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' ");
                                                                        _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (_txtTenSP.Text == "")
                                                                    {
                                                                        if (_cbHSX.SelectedIndex !=-1)
                                                                        {
                                                                            DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                                                     " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                                                     " FROM dbo.DMDonViTinh INNER JOIN " +
                                                                     " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                                                     " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                                                     " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "'and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' ");
                                                                            _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (_chHSX.IsChecked == false)
                                                                        {
                                                                            if (_cbNhomSP.SelectedIndex !=-1)
                                                                            {
                                                                                DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                                                            " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                                                            " FROM dbo.DMDonViTinh INNER JOIN " +
                                                                            " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                                                            " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                                                            " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' ");
                                                                                _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            if (_cbNhomSP.SelectedIndex !=-1 && _cbHSX.Text!="")
                                                                            {
                                                                                DataTable dt = cn.Loadtree("SELECT dbo.DMSanPham.maSanPham, dbo.DMSanPham.tenSanPham, dbo.DMSanPham.thongSoKT, dbo.DMSanPham.baoHanh, dbo.DMSanPham.giaBan, " +
                                                                         " dbo.DMNhomSP.tenNhomSP, dbo.DMDonViTinh.tenDVT, dbo.DMHangSX.tenHSX " +
                                                                         " FROM dbo.DMDonViTinh INNER JOIN " +
                                                                         " dbo.DMSanPham ON dbo.DMDonViTinh.maDVT = dbo.DMSanPham.maDVT INNER JOIN " +
                                                                         " dbo.DMHangSX ON dbo.DMSanPham.maHSX = dbo.DMHangSX.maHSX INNER JOIN " +
                                                                         " dbo.DMNhomSP ON dbo.DMSanPham.maNhomSP = dbo.DMNhomSP.maNhomSP where dbo.DMSanPham.maNhomSP = '" + _cbNhomSP.SelectedValue.ToString() + "' and dbo.DMSanPham.tenSanPham like N'%" + _txtTenSP.Text + "%' and dbo.DMSanPham.maHSX = '" + _cbHSX.SelectedValue.ToString() + "' and dbo.DMSanPham.giaBan between '" + TGB + "' and '" + DGB + "' ");
                                                                                _dtgdonvitinh.ItemsSource = dt.DefaultView;
                                                                            }
                                                                        }
                                                                    }


                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else { MessageBox.Show("Giá bán chưa hơp lệ", "Chú ý"); }
            }
        }



        private bool kttimkiem() 
        {
            try
            {
                float TGB1 = float.Parse(_txtTuGB.Text);
                float DGB1 = float.Parse(_txtDenGB.Text);
                
            }
            catch { return false; }
           
           
               
                    float TGB = float.Parse(_txtTuGB.Text);
                    float DGB = float.Parse(_txtDenGB.Text);
                    if (TGB >= 0 && DGB >= 0)
                    {
                        if (TGB <= DGB)
                        {
                            return true;
                        }
                    }
               
            return false;
        }
    
    
            }

        }

       
    

